﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration;

namespace ElValWeb.ValidatorClientAdapters {
    public class DomainValidatorClientAdapter : BaseClientAdapter<DomainValidatorData> {
        
        public DomainValidatorClientAdapter(DomainValidatorData validatorData) : base(validatorData) {
        }

        public override IEnumerable<ModelClientValidationRule> GetClientRules(Type ownerType) {
            
            var rule = new ModelClientValidationRule {
                ErrorMessage = ValidatorData.GetMessageTemplate(),
                ValidationType = "domainValidator"
            };
            
            rule.ValidationParameters["domain"] = ValidatorData.Domain.Select(a=>a.Name).ToArray();
            
            return new[] { Negate(rule, ValidatorData.Negated) };
        }
    }
}
